import java.util.Arrays;
import java.util.Random;

public class test {
    /**
     * 有序
     * @param array
     */
    public static void inorderArray(int[] array){
        for (int i = 0; i < array.length; i++) {
            array[i] = i;
        }
    }

    /**
     * 倒序
     * @param array
     */
    public static void notInorderArray(int[] array){
        for (int i = 0; i < array.length; i++) {
            array[i] = array.length- 1 - i;
        }
    }

    /**
     * 乱序
     * @param array
     */
    public static void initArray(int[] array){
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(array.length);
        }
    }

    //开始测试一些排序

    /**
     * 测试直接插入排序
     * @param array
     */
    public static void testInsertArray(int[] array){
        int[] tmpArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.insertSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("直接插入排序所用时间：" + (endTime - startTime));
    }

    /**
     * 希尔排序测试
     * @param array
     */
    public static void testShellArray(int[] array){
        int[] tmpArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.shellSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔排序所用时间：" + (endTime - startTime));
    }

    /**
     * 选择排序
     * @param array
     */
    public static void testSelectArray(int[] array){
        int[] tmpArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.selectSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("选择排序所用时间：" + (endTime - startTime));
    }

    public static void testQuickArray(int[] array){
        int[] tmpArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.quickSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("快速排序所用时间：" + (endTime - startTime));
    }
    public static void testMergeArray(int[] array){
        int[] tmpArray = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort.mergeSort(tmpArray);
        long endTime = System.currentTimeMillis();
        System.out.println("归并排序所用时间：" + (endTime - startTime));
    }

    public static void main07(String[] args) {
        System.out.println("给100000个数据");
        int[] array = new int[10_0000];
//        inorderArray(array);
//        notInorderArray(array);
        initArray(array);

//        testInsertArray(array);
//        testShellArray(array);
//        testSelectArray(array);
        testQuickArray(array);
        testMergeArray(array);

    }

    public static void main(String[] args) {
        int[] array = {1,9,5,6,8,8,6,5,4,3,10};
        Sort.countSort(array);
        System.out.println(Arrays.toString(array));
    }
    public static void main08(String[] args) {
        int[] array = {3,5,2,10,9,8,17};
        Sort.mergeSortNor(array);
        System.out.println(Arrays.toString(array));
    }

    public static void main06(String[] args) {
        int[] array = {3,5,2,10,9,8,17};
        Sort.mergeSort(array);
        System.out.println(Arrays.toString(array));
    }

    public static void main05(String[] args) {
        int[] array = {3,5,2,10,9,8,17};
        Sort.quickSort(array);
        System.out.println(Arrays.toString(array));
    }

    public static void main04(String[] args) {
        int[] array2 = {33,5,2,10,9,8,17};
        Sort.selectSort2(array2);
        System.out.println(Arrays.toString(array2));
    }
    public static void main03(String[] args) {
        int[] array = {3,5,2,10,9,8,17};
        Sort.selectSort(array);
        System.out.println(Arrays.toString(array));
    }
    public static void main02(String[] args) {
        int[] array = {3,5,2,10,9,8,17};
        Sort.shellSort(array);
        System.out.println(Arrays.toString(array));
    }



    public static void main01(String[] args) {
        int[] array = {3,5,2,10,9,8,17};
        Sort.insertSort(array);
        System.out.println(Arrays.toString(array));
    }
}
